package demo5;

import java.lang.reflect.Array;
import java.util.Arrays;

public class Text {
    public static void bubbleSort(Comparable[] comparables) {
        for (int i = 0; i < comparables.length - 1; i++) {
            for (int j = 0; j < comparables.length - 1 - i; j++) {
                if(comparables[j].compareTo(comparables[j + 1]) > 0) {
                    Comparable tmp = comparables[j+1];
                    comparables[j+1] = comparables[j];
                    comparables[j] = tmp;
                }
            }
        }
    }

    public static void main(String[] args) {
        Student student1 = new Student("xioaming", 11);
        Student student2 = new Student("wangming", 10);
        Student student3 = new Student("liming", 12);
        Student[] students = new Student[3];
        students[0] = student1;
        students[1] = student2;
        students[2] = student3;
        NameComparator nameComparator = new NameComparator();
        System.out.println(Arrays.toString(students));
        Arrays.sort(students,nameComparator);
        System.out.println(Arrays.toString(students));

    }

    public static void main2(String[] args) {
        Student student1 = new Student("xioaming", 11);
        Student student2 = new Student("wangming", 10);
        Student student3 = new Student("liming", 12);
        Student[] students = new Student[3];
        students[0] = student1;
        students[1] = student2;
        students[2] = student3;
        System.out.println(Arrays.toString(students));
        bubbleSort(students);
        System.out.println(Arrays.toString(students));


    }



    public static void main1(String[] args) {
        Student student1 = new Student("xioaming", 11);
        Student student2 = new Student("wangming", 10);

        int ret = student1.compareTo(student2);
        if(ret > 0) {
            System.out.println("studnet1>student2");
        }else if(ret == 0){
            System.out.println("studnet1=student2");
        }else{
            System.out.println("studnet1<student2");
        }
    }
}
